<template>
  <div class="sku-form">
    <div v-if="multipleSpec">
      <el-tabs type="border-card">
        <el-tab-pane label="商品规格">
          <div v-if="goodsSpuSpec == null || goodsSpuSpec.length <= 0" class="el-table__empty-block">
            <span class="el-table__empty-text">暂无数据</span>
          </div>
          <div class="spec-class-list">
              <div  class="spec-class-item" v-for="(item, index) in goodsSpuSpec">
                <p class="title">{{ item.serviceName }} {{ item.serviceName?'-':'' }} {{ item.name }}</p>
                <div class="content">
                  <div class="spec-class-item-content">
                    <el-row class="item header">
                      <el-col :span="12" class="left">关联服务</el-col>
                      <el-col :span="12" class="right">{{ item.serviceName }}</el-col>
                    </el-row>
                    <el-row class="item" v-for="(chil, idx) in [item.specClassList[0]||1,item.specClassList[1]||2,item.specClassList[2]||3]" :key="idx">
                      <el-col :span="12" class="left">{{ idx + 1}}级属性</el-col>
                      <el-col :span="12" class="right">{{ chil.name || '无' }}</el-col>
                    </el-row>
                  </div>
                </div>
              </div>
          </div>
          <div class="spec-class-bottom">
            <span class="add-spec-btn" @click="showSpecItem" v-if="specType=='1' && isSelectedCurrencySpuSpec">添加规格</span>
          </div>
        </el-tab-pane>
      </el-tabs>
      <el-tabs type="border-card" style="margin-top: 5px">
        <el-tab-pane label="商品SKU">
          <SkuTable
            :specData="goodsSpuSpecFilter"
            :goodsSku="goodsSku"
            :goodsSpuSpec="goodsSpuSpec"
            :skuTableType="skuType"
            :serviceType="serviceType"
            :specType="specType"
            v-if="goodsSpuSpec"
            @setGoodsSku="setGoodsSku"
          ></SkuTable>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script>
import SkuTable from "@/components/sku/sku-table-new.vue";

export default {
  components: {
    SkuTable
  },
  props: {
    form: {
      type: Object
    },
    goodsSpuSpec: {//规格类列表
      type: Array
    },
    goodsSku: {//sku列表
      type: Array
    },
    multipleSpec: {
      type: Boolean
    },
    skuType: {
      type: Boolean,
      default: false
    },
    specType: {
      type: String
    },
    serviceType: {
      type: String
    },
    isSelectedCurrencySpuSpec: {
      type: Boolean,
      default: false
    },
  },
  created() {

  },
  computed: {
    // 过滤掉属性名和属性值为空的数据规格项目
    goodsSpuSpecFilter() {
      return this.goodsSpuSpec.filter(
        item => item.value && item.leaf != null && item.leaf.length
      );
    }
  },
  watch: {
    form(val, oldVal) {
      if (val) {
      }
    },
    goodsSku: {
      deep: true,
      immediate: true,
      handler(val) {
        if (!this.isInitGoodsSku && val && val.length > 0) {
          this.isInitGoodsSku = true;
        }
      }
    },
    // goodsSpuSpec:{
    //   deep: true,
    //   handler(newList, oldList) {
    //     console.log('----->watch goodsSpuSpec');
    //     console.log(newList);
    //   },
    // }
  },
  data() {
    return {
      goodsSpecAdd: null,
      goodsSpecValueAdd: null,
      goodsSpecValue: null,
      goodsSpuSpecIndex: null,
      goodsSkuOne: null,
      rules: {},
      isInitGoodsSku: false
    };
  },
  inject:['showSpecItem'],
  methods: {
    setGoodsSku(){
      console.log('----------->setGoodsSku');
    }
  }
};
</script>

<style lang="scss" scoped>
.sku-form .el-tag + .el-tag {
  margin-left: 10px;
}

  .spec-class-item{
    float: left;
    margin: 5px;
    padding: 5px 10px;
    width: 277px;
    border: 1px solid #ddd;
    border-radius: 10px;

    .title{
      margin: 0;
    }
    .item{
      line-height: 22px;

      .left{
        text-align: left;
      }
      .right{
        text-align: right;
      }
    }
    .item.header{
      background-color: #ccc;
    }

  }

.spec-class-list{
  display: block;
  overflow: hidden;
}

.spec-class-bottom{
  display: block;
  text-align: center;

  .add-spec-btn{
    padding: 10px;
    text-align: center;
    color: #1890ff;
    cursor: pointer;
  }
}
</style>
